package com.qian.utils;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.message.BasicHttpResponse;

/**
 * 获取响应文件，即html
 * 
 * @author Qian
 *
 */
public class HTTPUtils {

	public static HttpResponse getRawHtml(HttpClient client, String personalUrl) {
		// 2、创建某种连接方法的实例，在这里是GetMethod。在 GetMethod 的构造函数中传入待连接的地址
		// 获取响应文件，即html，采用get方法获取响应数据
		HttpGet getMethod = new HttpGet(personalUrl);
		HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
		try {
			// 3、调用第一步中创建好的实例的 execute方法来执行第二步中创建好的 method 实例
			// 执行get方法
			response = client.execute(getMethod);
		} catch (IOException e) {
			e.printStackTrace();

		} finally {
			// 释放链接
			// getMethod.releaseConnection();
			// getMethod.abort();
		}
		return response;
	}
}
